const  config=require('./config.json');
const main = require('./main');
const fs = require('fs');
const path = require('path');


(async ()=> {
   console.time('全部任务耗时');

   await new Promise(async (resolve, reject) => {
        let mainImgArr = getFiles(config.大图文件夹);
        await main.main(mainImgArr,getFiles(config.小图文件夹));
        resolve();
        
   })
   console.timeEnd('全部任务耗时');

})();

/**获取文件夹下所有文件 */
function getFiles(folderPath) {
    let filesList = [];
    if(!fs.existsSync(folderPath)){
        console.log('LPTEXT','文件夹不存在');
        return filesList;
    };
    let filesAndFolders  = fs.readdirSync(folderPath);
    const files  = filesAndFolders.filter(fileOrFolder =>
        fs.statSync(path.join(folderPath, fileOrFolder)).isFile()
    );

    files.forEach(file => {
        filesList.push(path.join(folderPath, file));
    });

    return filesList;
}
